package constants 
{
	import flash.geom.Rectangle;
	import flash.utils.getDefinitionByName;
	import flash.utils.getQualifiedClassName;
	import points.CollidePoint;
	import structures.Structure;
	/**
	 * ...
	 * @author parasitic
	 */
	public class utils 
	{

		public static const screen:int = 400;
		public static const limit:int = 600;
		public static const Rect:Rectangle = new Rectangle(-limit, -limit, (limit*2)+screen, (limit*2)+screen);
		public static const None:int = -1;
		public static var pointIndex:int = -1;
		
		public static function round(n:Number):Number
		{
			return int(n / 10) * 10;
		}
		
		public static function getDistance(xA:Number, yA:Number, xB:Number, yB:Number):Number
		{
			var d_x:Number = xA - xB;
			var d_y:Number = yA - yB;
			
			return Math.sqrt((d_x * d_x) + (d_y * d_y));
		}
		
		public static function getClass(obj:Object):Class
		{
			return Class(getDefinitionByName(getQualifiedClassName(obj)));
		}
		
		public static function getNewIndex():int
		{
			pointIndex++;
			return pointIndex;
		}
		
		public static function arrayPopItem(a:Array, item:CollidePoint):CollidePoint
		{
			var ret:CollidePoint = null;
			try 
			{
				var i:int = a.indexOf(item);
				ret = a[i];
				a.splice(i, 1);
				return ret;
			}
			catch (err:Error)
			{
				trace("arrayPopItem: " + err);
			}
			return ret;
		}
		
		public static function arrayPopIndex(a:Array, index:int):void
		{
			try
			{
				a.splice(index, 1);
			}
			catch (err:Error)
			{
				trace("arrayPopIndex " + err);
			}
		}
		
		public static function arrayClear(a:Array, n:int):void
		{
			try 
			{
				a.splice(n, a.length - n);
			}
			catch (err:Error)
			{
				trace("arrayClear " + err);
			}
			
		}
		
	}

}